<html>

<?php
    /*
    * This script asks for the DBMS server credentials and for
    * the type of DBMS checks whether the settings work and
    * then produces a success message if working.
    * A link to the next page is produced.
    */
    if(isset($_POST['selDBMS']))
        $dbms = $_POST['selDBMS'];
    $pathAdjust = "../";
    @include "{$pathAdjust}initIncludePaths.inc";
    @include "dbFac.inc";
    @include('display.inc');
    $disp = new Display();
 ?>
     <head>
        <title>2DBv2 Setup - DBMS credentials</title>
        <?php   @include "metaTags.inc";
                @include "head.inc";  ?>
    </head>
    <body>
 <?php
    $dbfac = new DatabaseFactory();
    if($dbfac->testSettings()  && !isset($_POST['submit'])) {
        //Server setup is already working so the next installation script should be called.
        echo "
            <script type=\"text/javascript\" language=\"JavaScript\">
                this.location.href=\"setupAdmin.php\";
            </script>
        ";
    }
    if(isset($dbms)) { //The form was submitted and data is now available.
        $dbfac = new DatabaseFactory($dbms,$_POST['serverPath'],$_POST['dbName'],$_POST['userName'],$_POST['password']);
        $conDataOK = $dbfac->testSettings();
        if($conDataOK) {
            $dbfac->writeSettings();
            $disp->frameText("good", "Step 2 of 4 successfully completed. <a href=\"setupAdmin.php\">Next step</a>.");
        } else
            $disp->frameText("bad", "There is a problem with your settings a connection could not be established.");
     } else {
         //
     }
     $dbmss = $dbfac->determineAvailableDBMS();
?>
        <div>
            Some info needed here.
        </div>
        <br />
        <form action="setupServer.php" method="post">
            <table>
                <tr>
                    <td>Choose DBMS</td>
                    <td>
                        <select name="selDBMS">
                            <?php
                                foreach($dbmss as $dbms) {
                                    if($dbms == $dbfac->getDbms())
                                        echo "<option value='$dbms' selected>$dbms</option>\n";
                                    else
                                        echo "<option value='$dbms'>$dbms</option>\n";
                                }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Server Path</td>
                    <td>
                        <input type="text" name="serverPath" value="<?php echo $dbfac->getHost(); ?>" />
                    </td>
                </tr>
                <tr>
                    <td>Database Name</td>
                    <td>
                        <input type="text" name="dbName" value="<?php echo $dbfac->getDbName(); ?>" />
                    </td>
                </tr>
                <tr>
                    <td>User Name</td>
                    <td>
                        <input type="text" name="userName" value="<?php echo $dbfac->getUser(); ?>" />
                    </td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td>
                        <input type="password" name="password" value="<?php echo $dbfac->getPass(); ?>" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" name="submit" value="Select" />
                        <input type="submit" name="cancel" value="Cancel" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>